package com.lzx.service.impl;

import com.lzx.dao.UserDao;
import com.lzx.service.UserService;
import org.springframework.beans.factory.InitializingBean;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class UserServiceImpl implements UserService, InitializingBean {

    public UserServiceImpl() {
        System.out.println("UserServiceImpl实例化（wucan）");
    }

    public UserServiceImpl(String lover, Integer age) {
        System.out.println("UserServiceImpl实例化（youcan）；lover=" + lover + "，age=" + age);
    }

    // 注入 List集合
    private List<String> stringList;

    public void setStringList(List<String> stringList) {
        this.stringList = stringList;
    }

    // 注入 UserDao 的 List集合
    private List<UserDao> userDaoList;

    public void setUserDaoList(List<UserDao> userDaoList) {
        this.userDaoList = userDaoList;
    }

    // 注入 Set 集合
    private Set<String> stringSet;

    public void setStringSet(Set<String> stringSet) {
        this.stringSet = stringSet;
    }

    // 注入 UserDao 的 Set集合
    private Set<UserDao> userDaoSet;

    public void setUserDaoSet(Set<UserDao> userDaoSet) {
        this.userDaoSet = userDaoSet;
    }

    // 注入 Map集合
    private Map<String, UserDao> map;

    public void setMap(Map<String, UserDao> map) {
        this.map = map;
    }

    // 注入 properties : 字符串的键值对
    private Properties properties;

    public void setProperties(Properties properties) {
        this.properties = properties;
    }

    public void init() {
        System.out.println("初始化方法...");
    }

    public void destroy() {
        System.out.println("销毁方法...");
    }

    private UserDao userDao;

    // BeanFactory 去调用该方法，从工厂中去获取 userDao 设置到此处。应该就是：注入 UserDao
    public void setUserDao(UserDao userDao) {
        System.out.println("属性设置完毕...");
        this.userDao = userDao;
    }

    // 在属性设置之后调用，如：在给 UserService 设置 UserDao 之后调用
    // 早于 init-method 属性之前执行
    // 执行流程：构造函数执行，实例化完成 -> 属性设置 -> afterPropertiesSet -> init-method 配置的初始化方法
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet被调用...");
    }

    public void show() {
        System.out.println("stringList = " + stringList);
        System.out.println("userDaoList = " + userDaoList);
        System.out.println("------------------------");
        System.out.println("stringSet = " + stringSet);
        System.out.println("userDaoSet = " + userDaoSet);
        System.out.println("------------------------");
        System.out.println("map = " + map);
        System.out.println("------------------------");
        System.out.println("properties = " + properties);
        System.out.println("userDao = " + userDao);
    }
}
